// Copyright (c) Lawrence Livermore National Security, LLC and other VisIt
// Project developers.  See the top-level LICENSE file for dates and other
// details.  No copyright assignment is required to contribute to VisIt.

#include <PyTubeAttributes.h>
#include <ObserverToCallback.h>
#include <stdio.h>
#include <Py2and3Support.h>

// ****************************************************************************
// Module: PyTubeAttributes
//
// Purpose:
//   This class contains attributes for the tube operator.
//
// Note:       Autogenerated by xml2python. Do not modify by hand!
//
// Programmer: xml2python
// Creation:   omitted
//
// ****************************************************************************

//
// This struct contains the Python type information and a TubeAttributes.
//
struct TubeAttributesObject
{
    PyObject_HEAD
    TubeAttributes *data;
    bool        owns;
    PyObject   *parent;
};

//
// Internal prototypes
//
static PyObject *NewTubeAttributes(int);
std::string
PyTubeAttributes_ToString(const TubeAttributes *atts, const char *prefix, const bool forLogging)
{
    std::string str;
    char tmpStr[1000];

    if(atts->GetScaleByVarFlag())
        snprintf(tmpStr, 1000, "%sscaleByVarFlag = 1\n", prefix);
    else
        snprintf(tmpStr, 1000, "%sscaleByVarFlag = 0\n", prefix);
    str += tmpStr;
    const char *tubeRadiusType_names = "FractionOfBBox, Absolute";
    switch (atts->GetTubeRadiusType())
    {
      case TubeAttributes::FractionOfBBox:
          snprintf(tmpStr, 1000, "%stubeRadiusType = %sFractionOfBBox  # %s\n", prefix, prefix, tubeRadiusType_names);
          str += tmpStr;
          break;
      case TubeAttributes::Absolute:
          snprintf(tmpStr, 1000, "%stubeRadiusType = %sAbsolute  # %s\n", prefix, prefix, tubeRadiusType_names);
          str += tmpStr;
          break;
      default:
          break;
    }

    snprintf(tmpStr, 1000, "%sradiusFractionBBox = %g\n", prefix, atts->GetRadiusFractionBBox());
    str += tmpStr;
    snprintf(tmpStr, 1000, "%sradiusAbsolute = %g\n", prefix, atts->GetRadiusAbsolute());
    str += tmpStr;
    snprintf(tmpStr, 1000, "%sscaleVariable = \"%s\"\n", prefix, atts->GetScaleVariable().c_str());
    str += tmpStr;
    snprintf(tmpStr, 1000, "%sfineness = %d\n", prefix, atts->GetFineness());
    str += tmpStr;
    if(atts->GetCapping())
        snprintf(tmpStr, 1000, "%scapping = 1\n", prefix);
    else
        snprintf(tmpStr, 1000, "%scapping = 0\n", prefix);
    str += tmpStr;
    return str;
}

static PyObject *
TubeAttributes_Notify(PyObject *self, PyObject *args)
{
    TubeAttributesObject *obj = (TubeAttributesObject *)self;
    obj->data->Notify();
    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
TubeAttributes_SetScaleByVarFlag(PyObject *self, PyObject *args)
{
    TubeAttributesObject *obj = (TubeAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    bool cval = bool(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ bool");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ bool");
    }

    Py_XDECREF(packaged_args);

    // Set the scaleByVarFlag in the object.
    obj->data->SetScaleByVarFlag(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
TubeAttributes_GetScaleByVarFlag(PyObject *self, PyObject *args)
{
    TubeAttributesObject *obj = (TubeAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(obj->data->GetScaleByVarFlag()?1L:0L);
    return retval;
}

/*static*/ PyObject *
TubeAttributes_SetTubeRadiusType(PyObject *self, PyObject *args)
{
    TubeAttributesObject *obj = (TubeAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if ((val == -1 && PyErr_Occurred()) || long(cval) != val)
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }

    if (cval < 0 || cval >= 2)
    {
        std::stringstream ss;
        ss << "An invalid tubeRadiusType value was given." << std::endl;
        ss << "Valid values are in the range [0,1]." << std::endl;
        ss << "You can also use the following symbolic names:";
        ss << " FractionOfBBox";
        ss << ", Absolute";
        return PyErr_Format(PyExc_ValueError, ss.str().c_str());
    }

    Py_XDECREF(packaged_args);

    // Set the tubeRadiusType in the object.
    obj->data->SetTubeRadiusType(TubeAttributes::TubeRadiusType(cval));

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
TubeAttributes_GetTubeRadiusType(PyObject *self, PyObject *args)
{
    TubeAttributesObject *obj = (TubeAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetTubeRadiusType()));
    return retval;
}

/*static*/ PyObject *
TubeAttributes_SetRadiusFractionBBox(PyObject *self, PyObject *args)
{
    TubeAttributesObject *obj = (TubeAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    double val = PyFloat_AsDouble(args);
    double cval = double(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ double");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(double(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ double");
    }

    Py_XDECREF(packaged_args);

    // Set the radiusFractionBBox in the object.
    obj->data->SetRadiusFractionBBox(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
TubeAttributes_GetRadiusFractionBBox(PyObject *self, PyObject *args)
{
    TubeAttributesObject *obj = (TubeAttributesObject *)self;
    PyObject *retval = PyFloat_FromDouble(obj->data->GetRadiusFractionBBox());
    return retval;
}

/*static*/ PyObject *
TubeAttributes_SetRadiusAbsolute(PyObject *self, PyObject *args)
{
    TubeAttributesObject *obj = (TubeAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    double val = PyFloat_AsDouble(args);
    double cval = double(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ double");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(double(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ double");
    }

    Py_XDECREF(packaged_args);

    // Set the radiusAbsolute in the object.
    obj->data->SetRadiusAbsolute(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
TubeAttributes_GetRadiusAbsolute(PyObject *self, PyObject *args)
{
    TubeAttributesObject *obj = (TubeAttributesObject *)self;
    PyObject *retval = PyFloat_FromDouble(obj->data->GetRadiusAbsolute());
    return retval;
}

/*static*/ PyObject *
TubeAttributes_SetScaleVariable(PyObject *self, PyObject *args)
{
    TubeAttributesObject *obj = (TubeAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged as first member of a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyUnicode_Check(packaged_args))
            args = packaged_args;
    }

    if (!PyUnicode_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a unicode string");
    }

    char const *val = PyUnicode_AsUTF8(args);
    std::string cval = std::string(val);

    if (val == 0 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as utf8 string");
    }

    Py_XDECREF(packaged_args);

    // Set the scaleVariable in the object.
    obj->data->SetScaleVariable(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
TubeAttributes_GetScaleVariable(PyObject *self, PyObject *args)
{
    TubeAttributesObject *obj = (TubeAttributesObject *)self;
    PyObject *retval = PyString_FromString(obj->data->GetScaleVariable().c_str());
    return retval;
}

/*static*/ PyObject *
TubeAttributes_SetFineness(PyObject *self, PyObject *args)
{
    TubeAttributesObject *obj = (TubeAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ int");
    }

    Py_XDECREF(packaged_args);

    // Set the fineness in the object.
    obj->data->SetFineness(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
TubeAttributes_GetFineness(PyObject *self, PyObject *args)
{
    TubeAttributesObject *obj = (TubeAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetFineness()));
    return retval;
}

/*static*/ PyObject *
TubeAttributes_SetCapping(PyObject *self, PyObject *args)
{
    TubeAttributesObject *obj = (TubeAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    bool cval = bool(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ bool");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ bool");
    }

    Py_XDECREF(packaged_args);

    // Set the capping in the object.
    obj->data->SetCapping(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
TubeAttributes_GetCapping(PyObject *self, PyObject *args)
{
    TubeAttributesObject *obj = (TubeAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(obj->data->GetCapping()?1L:0L);
    return retval;
}



PyMethodDef PyTubeAttributes_methods[TUBEATTRIBUTES_NMETH] = {
    {"Notify", TubeAttributes_Notify, METH_VARARGS},
    {"SetScaleByVarFlag", TubeAttributes_SetScaleByVarFlag, METH_VARARGS},
    {"GetScaleByVarFlag", TubeAttributes_GetScaleByVarFlag, METH_VARARGS},
    {"SetTubeRadiusType", TubeAttributes_SetTubeRadiusType, METH_VARARGS},
    {"GetTubeRadiusType", TubeAttributes_GetTubeRadiusType, METH_VARARGS},
    {"SetRadiusFractionBBox", TubeAttributes_SetRadiusFractionBBox, METH_VARARGS},
    {"GetRadiusFractionBBox", TubeAttributes_GetRadiusFractionBBox, METH_VARARGS},
    {"SetRadiusAbsolute", TubeAttributes_SetRadiusAbsolute, METH_VARARGS},
    {"GetRadiusAbsolute", TubeAttributes_GetRadiusAbsolute, METH_VARARGS},
    {"SetScaleVariable", TubeAttributes_SetScaleVariable, METH_VARARGS},
    {"GetScaleVariable", TubeAttributes_GetScaleVariable, METH_VARARGS},
    {"SetFineness", TubeAttributes_SetFineness, METH_VARARGS},
    {"GetFineness", TubeAttributes_GetFineness, METH_VARARGS},
    {"SetCapping", TubeAttributes_SetCapping, METH_VARARGS},
    {"GetCapping", TubeAttributes_GetCapping, METH_VARARGS},
    {NULL, NULL}
};

//
// Type functions
//

static void
TubeAttributes_dealloc(PyObject *v)
{
   TubeAttributesObject *obj = (TubeAttributesObject *)v;
   if(obj->parent != 0)
       Py_DECREF(obj->parent);
   if(obj->owns)
       delete obj->data;
}

static PyObject *TubeAttributes_richcompare(PyObject *self, PyObject *other, int op);
PyObject *
PyTubeAttributes_getattr(PyObject *self, char *name)
{
    if(strcmp(name, "scaleByVarFlag") == 0)
        return TubeAttributes_GetScaleByVarFlag(self, NULL);
    if(strcmp(name, "tubeRadiusType") == 0)
        return TubeAttributes_GetTubeRadiusType(self, NULL);
    if(strcmp(name, "FractionOfBBox") == 0)
        return PyInt_FromLong(long(TubeAttributes::FractionOfBBox));
    if(strcmp(name, "Absolute") == 0)
        return PyInt_FromLong(long(TubeAttributes::Absolute));

    if(strcmp(name, "radiusFractionBBox") == 0)
        return TubeAttributes_GetRadiusFractionBBox(self, NULL);
    if(strcmp(name, "radiusAbsolute") == 0)
        return TubeAttributes_GetRadiusAbsolute(self, NULL);
    if(strcmp(name, "scaleVariable") == 0)
        return TubeAttributes_GetScaleVariable(self, NULL);
    if(strcmp(name, "fineness") == 0)
        return TubeAttributes_GetFineness(self, NULL);
    if(strcmp(name, "capping") == 0)
        return TubeAttributes_GetCapping(self, NULL);


    // Add a __dict__ answer so that dir() works
    if (!strcmp(name, "__dict__"))
    {
        PyObject *result = PyDict_New();
        for (int i = 0; PyTubeAttributes_methods[i].ml_meth; i++)
            PyDict_SetItem(result,
                PyString_FromString(PyTubeAttributes_methods[i].ml_name),
                PyString_FromString(PyTubeAttributes_methods[i].ml_name));
        return result;
    }

    return Py_FindMethod(PyTubeAttributes_methods, self, name);
}

int
PyTubeAttributes_setattr(PyObject *self, char *name, PyObject *args)
{
    PyObject NULL_PY_OBJ;
    PyObject *obj = &NULL_PY_OBJ;

    if(strcmp(name, "scaleByVarFlag") == 0)
        obj = TubeAttributes_SetScaleByVarFlag(self, args);
    else if(strcmp(name, "tubeRadiusType") == 0)
        obj = TubeAttributes_SetTubeRadiusType(self, args);
    else if(strcmp(name, "radiusFractionBBox") == 0)
        obj = TubeAttributes_SetRadiusFractionBBox(self, args);
    else if(strcmp(name, "radiusAbsolute") == 0)
        obj = TubeAttributes_SetRadiusAbsolute(self, args);
    else if(strcmp(name, "scaleVariable") == 0)
        obj = TubeAttributes_SetScaleVariable(self, args);
    else if(strcmp(name, "fineness") == 0)
        obj = TubeAttributes_SetFineness(self, args);
    else if(strcmp(name, "capping") == 0)
        obj = TubeAttributes_SetCapping(self, args);

    if (obj != NULL && obj != &NULL_PY_OBJ)
        Py_DECREF(obj);

    if (obj == &NULL_PY_OBJ)
    {
        obj = NULL;
        PyErr_Format(PyExc_NameError, "name '%s' is not defined", name);
    }
    else if (obj == NULL && !PyErr_Occurred())
        PyErr_Format(PyExc_RuntimeError, "unknown problem with '%s'", name);

    return (obj != NULL) ? 0 : -1;
}

static int
TubeAttributes_print(PyObject *v, FILE *fp, int flags)
{
    TubeAttributesObject *obj = (TubeAttributesObject *)v;
    fprintf(fp, "%s", PyTubeAttributes_ToString(obj->data, "",false).c_str());
    return 0;
}

PyObject *
TubeAttributes_str(PyObject *v)
{
    TubeAttributesObject *obj = (TubeAttributesObject *)v;
    return PyString_FromString(PyTubeAttributes_ToString(obj->data,"", false).c_str());
}

//
// The doc string for the class.
//
#if PY_MAJOR_VERSION > 2 || (PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION >= 5)
static const char *TubeAttributes_Purpose = "This class contains attributes for the tube operator.";
#else
static char *TubeAttributes_Purpose = "This class contains attributes for the tube operator.";
#endif

//
// Python Type Struct Def Macro from Py2and3Support.h
//
//         VISIT_PY_TYPE_OBJ( VPY_TYPE,
//                            VPY_NAME,
//                            VPY_OBJECT,
//                            VPY_DEALLOC,
//                            VPY_PRINT,
//                            VPY_GETATTR,
//                            VPY_SETATTR,
//                            VPY_STR,
//                            VPY_PURPOSE,
//                            VPY_RICHCOMP,
//                            VPY_AS_NUMBER)

//
// The type description structure
//

VISIT_PY_TYPE_OBJ(TubeAttributesType,         \
                  "TubeAttributes",           \
                  TubeAttributesObject,       \
                  TubeAttributes_dealloc,     \
                  TubeAttributes_print,       \
                  PyTubeAttributes_getattr,   \
                  PyTubeAttributes_setattr,   \
                  TubeAttributes_str,         \
                  TubeAttributes_Purpose,     \
                  TubeAttributes_richcompare, \
                  0); /* as_number*/

//
// Helper function for comparing.
//
static PyObject *
TubeAttributes_richcompare(PyObject *self, PyObject *other, int op)
{
    // only compare against the same type 
    if ( Py_TYPE(self) != &TubeAttributesType
         || Py_TYPE(other) != &TubeAttributesType)
    {
        Py_INCREF(Py_NotImplemented);
        return Py_NotImplemented;
    }

    PyObject *res = NULL;
    TubeAttributes *a = ((TubeAttributesObject *)self)->data;
    TubeAttributes *b = ((TubeAttributesObject *)other)->data;

    switch (op)
    {
       case Py_EQ:
           res = (*a == *b) ? Py_True : Py_False;
           break;
       case Py_NE:
           res = (*a != *b) ? Py_True : Py_False;
           break;
       default:
           res = Py_NotImplemented;
           break;
    }

    Py_INCREF(res);
    return res;
}

//
// Helper functions for object allocation.
//

static TubeAttributes *defaultAtts = 0;
static TubeAttributes *currentAtts = 0;

static PyObject *
NewTubeAttributes(int useCurrent)
{
    TubeAttributesObject *newObject;
    newObject = PyObject_NEW(TubeAttributesObject, &TubeAttributesType);
    if(newObject == NULL)
        return NULL;
    if(useCurrent && currentAtts != 0)
        newObject->data = new TubeAttributes(*currentAtts);
    else if(defaultAtts != 0)
        newObject->data = new TubeAttributes(*defaultAtts);
    else
        newObject->data = new TubeAttributes;
    newObject->owns = true;
    newObject->parent = 0;
    return (PyObject *)newObject;
}

static PyObject *
WrapTubeAttributes(const TubeAttributes *attr)
{
    TubeAttributesObject *newObject;
    newObject = PyObject_NEW(TubeAttributesObject, &TubeAttributesType);
    if(newObject == NULL)
        return NULL;
    newObject->data = (TubeAttributes *)attr;
    newObject->owns = false;
    newObject->parent = 0;
    return (PyObject *)newObject;
}

///////////////////////////////////////////////////////////////////////////////
//
// Interface that is exposed to the VisIt module.
//
///////////////////////////////////////////////////////////////////////////////

PyObject *
TubeAttributes_new(PyObject *self, PyObject *args)
{
    int useCurrent = 0;
    if (!PyArg_ParseTuple(args, "i", &useCurrent))
    {
        if (!PyArg_ParseTuple(args, ""))
            return NULL;
        else
            PyErr_Clear();
    }

    return (PyObject *)NewTubeAttributes(useCurrent);
}

//
// Plugin method table. These methods are added to the visitmodule's methods.
//
static PyMethodDef TubeAttributesMethods[] = {
    {"TubeAttributes", TubeAttributes_new, METH_VARARGS},
    {NULL,      NULL}        /* Sentinel */
};

static Observer *TubeAttributesObserver = 0;

std::string
PyTubeAttributes_GetLogString()
{
    std::string s("TubeAtts = TubeAttributes()\n");
    if(currentAtts != 0)
        s += PyTubeAttributes_ToString(currentAtts, "TubeAtts.", true);
    return s;
}

static void
PyTubeAttributes_CallLogRoutine(Subject *subj, void *data)
{
    typedef void (*logCallback)(const std::string &);
    logCallback cb = (logCallback)data;

    if(cb != 0)
    {
        std::string s("TubeAtts = TubeAttributes()\n");
        s += PyTubeAttributes_ToString(currentAtts, "TubeAtts.", true);
        cb(s);
    }
}

void
PyTubeAttributes_StartUp(TubeAttributes *subj, void *data)
{
    if(subj == 0)
        return;

    currentAtts = subj;
    PyTubeAttributes_SetDefaults(subj);

    //
    // Create the observer that will be notified when the attributes change.
    //
    if(TubeAttributesObserver == 0)
    {
        TubeAttributesObserver = new ObserverToCallback(subj,
            PyTubeAttributes_CallLogRoutine, (void *)data);
    }

}

void
PyTubeAttributes_CloseDown()
{
    delete defaultAtts;
    defaultAtts = 0;
    delete TubeAttributesObserver;
    TubeAttributesObserver = 0;
}

PyMethodDef *
PyTubeAttributes_GetMethodTable(int *nMethods)
{
    *nMethods = 1;
    return TubeAttributesMethods;
}

bool
PyTubeAttributes_Check(PyObject *obj)
{
    return (obj->ob_type == &TubeAttributesType);
}

TubeAttributes *
PyTubeAttributes_FromPyObject(PyObject *obj)
{
    TubeAttributesObject *obj2 = (TubeAttributesObject *)obj;
    return obj2->data;
}

PyObject *
PyTubeAttributes_New()
{
    return NewTubeAttributes(0);
}

PyObject *
PyTubeAttributes_Wrap(const TubeAttributes *attr)
{
    return WrapTubeAttributes(attr);
}

void
PyTubeAttributes_SetParent(PyObject *obj, PyObject *parent)
{
    TubeAttributesObject *obj2 = (TubeAttributesObject *)obj;
    obj2->parent = parent;
}

void
PyTubeAttributes_SetDefaults(const TubeAttributes *atts)
{
    if(defaultAtts)
        delete defaultAtts;

    defaultAtts = new TubeAttributes(*atts);
}

